package com.zzq.handler;

import com.zzq.exception.LoginException;
import com.zzq.exception.SwitchException;
import com.zzq.exception.ZzqException;
import com.zzq.result.SmileResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description: 自定义异常处理
 * @author: DT
 * @date: 2021/4/19 21:17
 * @version: v1.0
 */
@ControllerAdvice
@Slf4j
public class MyExceptionContoller {

    @ExceptionHandler(value = ZzqException.class)
    @ResponseBody
    public SmileResult exceptionHandler(ZzqException e){
        log.warn("全局异常捕获>>>:{}"+e.getMessage());
        if (e instanceof LoginException){
            SmileResult result = new SmileResult<>(303,"登录异常"+e.getMessage());
            return result;
        }
        return SmileResult.error( "全局异常捕获,错误原因>>>"+e.getMessage());
    }
}
